<?php
	
	// 函数: 返回当前 path_info 方式的URL, 并可按参数替换 segment

	function smarty_function_url($params, &$smarty) {
		global $segment;
		$s = $segment;
		//
		foreach($params as $k => $v)
			if(preg_match("/s(\d)/i", $k, $matches)) $s[$matches[1]] = $v;

 		$str = $smarty->_tpl_vars["site_admin"];
		//$str .= $smarty->_tpl_vars["uri"];
		//str_replace("//", "/", $str);

		$maxkey = 0;
		foreach($s as $k => $v) $maxkey=($k>$maxkey)?$k:$maxkey;
		for($i=1;$i<=$maxkey;$i++) $str .= "page=". (empty($s[$i])?"0":$s[$i]);	
	$str .= empty($_SERVER["QUERY_STRING"])?"":"&".preg_replace( "/page=\d+\&/i","", $_SERVER['QUERY_STRING']);

		return str_replace("//", "/", $str);
	}
	
?>